<template>
  <div>
    <div class="box">
      <div style="width: 30%; padding-top: 10%">
        <h2>LOGIN</h2>
        <div>
          <input v-model="username" type="text" placeholder="用户名" size="large">
        </div>
        <div class="box">
          <input v-model="password" type="password" placeholder="密码" size="large">
        </div>
      </div>
    </div>
    <div class="box">
      <div class="box-in">
        <button shape="circle" size="large" type="primary" @click="userLogin()">登录</button>
        <button shape="circle" size="large" type="info" style="margin-left:10px" @click="userRegister()">注册</button>
        <button shape="circle" size="large" type="text" style="margin-left:10px" @click="findPassword()">忘记密码</button>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      username: "",
      password: ""
    };
  },
  methods: {
    userLogin(event) {
      axios({
            url:'http://jiangtest.free.idcfengye.com/loginS',
            method:'post',
            data:{
              username: this.username,
              password: this.password
            },
            headers:{
              "Content-Type":"application/json",
            }
            }).then(res => {
                if (res.data.status == 200) {
                        alert("ok");
                        localStorage.setItem("token",JAON.stringify(res.data.token));
                        console.log(Storage.token)
                        localStorage.setItem("username",JSON.stringify(res.data.userLogin))
                      } else {
                          alert("err");
                      };
                            })
                        },
      
    userRegister(event) {
      axios({
              url:'http://jiangtest.free.idcfengye.com/get',
              method:'post',
              data:JSON.stringify({
                username: this.username,
              password: this.password
              }) ,
              headers:{
                "Content-Type":"application/json",
                "token":Storage.token
              }
              }).then(res => {
                  console.log(res);
              })
                  },
    // 找回密码
    findPassword(event) {
      this.$router.push({ path: "findPassword" });
    }
  }
};
</script>

<style scoped lang="css">
.box {
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 10px;
}

.box-in {
  margin-top: 20px;
}
h2 {
  text-align: center;
  margin-bottom: 20px;
}
</style>
